package com.snowRemovingUser.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.snowRemovingUser.domain.TRoadManage;
import com.snowRemovingUser.service.ITRoadManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 路段管理Controller
 *
 * @author lg
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/snowRemoving/roadmanage")
public class TRoadManageController extends BaseController
{
    @Autowired
    private ITRoadManageService tRoadManageService;

    /**
     * 查询路段管理列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:roadmanage:list')")
    @GetMapping("/list")
    public AjaxResult list(TRoadManage tRoadManage)
    {
        List<TRoadManage> list = tRoadManageService.selectTRoadManageList(tRoadManage);
        return success(list);
    }

    /**
     * 导出路段管理列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:roadmanage:export')")
    @Log(title = "路段管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRoadManage tRoadManage)
    {
        List<TRoadManage> list = tRoadManageService.selectTRoadManageList(tRoadManage);
        ExcelUtil<TRoadManage> util = new ExcelUtil<TRoadManage>(TRoadManage.class);
        util.exportExcel(response, list, "路段管理数据");
    }

    /**
     * 获取路段管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:roadmanage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tRoadManageService.selectTRoadManageById(id));
    }

    /**
     * 新增路段管理
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:roadmanage:add')")
    @Log(title = "路段管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRoadManage tRoadManage)
    {
        return toAjax(tRoadManageService.insertTRoadManage(tRoadManage));
    }

    /**
     * 修改路段管理
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:roadmanage:edit')")
    @Log(title = "路段管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRoadManage tRoadManage)
    {
        return toAjax(tRoadManageService.updateTRoadManage(tRoadManage));
    }

    /**
     * 删除路段管理
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:roadmanage:remove')")
    @Log(title = "路段管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tRoadManageService.deleteTRoadManageByIds(ids));
    }
}
